package com.space.user.domain.info.service;

import com.space.user.domain.info.entity.UserInfo;
import com.space.user.domain.info.repository.InfoRepository;
import com.space.user.domain.info.valueobject.Account;
import com.space.user.domain.info.valueobject.UserId;
import lombok.NonNull;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @author <a href="mailto:414563035@qq.com">Bedroom</a>
 * @date 2021/4/13 6:57 下午
 */
@Service
public class UserInfoDomainService {
    @Autowired
    private InfoRepository infoRepository;

    public UserInfo create(UserInfo userInfo) {
        return infoRepository.save(userInfo);
    }

    public UserInfo getBasicInfo(@NonNull UserId userId) {
        final UserInfo userInfo = infoRepository.find(userId);
        return userInfo.isExist();
    }

    public UserInfo linkAccount(@NonNull UserInfo userInfo,  Account account) {
        return userInfo.linkAccount(account);
    }

    public void modify(UserInfo userInfo) {
        infoRepository.save(userInfo);
    }
}
